//
//  NSArray+Custom.m
//  coyote
//
//  Created by LeoHao on 14/12/17.
//  Copyright (c) 2014年 500wan. All rights reserved.
//

#import "NSArray+Custom.h"
//int hdcommon = 3;
//int hdcommon1;
__attribute__((constructor(101))) static void common_before1(void)
{
    printf("-=before1\n");
}
__attribute__((constructor(101))) static void common_before2(void)
{
    printf("-=before2\n");
}

@implementation NSArray (Custom)

/**
 @desc      检查数据是否为有效的数组
 @author    Created by LeoHao on 2014-12-17
 */
+(BOOL)isAvailableArray:(id)array{
    if (!array) {
        return false;
    }
    if (![array isKindOfClass:[NSArray class]]) {
        return false;
    }
    if ([array count] == 0) {
        return false;
    }
    return true;
}

-(BOOL) isContainObj:(id) obj sameBlock:(BOOL(^)(id obj1, id obj2)) sameBlock{
    
    for (NSInteger index = 0; index < self.count; index += 1) {
        
        BOOL isSame = sameBlock(obj,self[index]);
        if (isSame) {
            return true;
        }
        
    }
    return false;
    
    
}

-(BOOL) isContainArrayEle:(NSArray *) array{
    if (array == nil) {
        return false;
    }
    
    for (id obj in array) {
        if (![self containsObject:obj]) {
            return false;
        }
    }
    return true;
    
}

-(BOOL) isEqualArrayEleIgnoreOrder:(NSArray *) array{
    if (array == nil) {
        return false;
    }
    
    if ([self isContainArrayEle:array] && [array isContainArrayEle:self]) {
        return true;
    }
    
    return false;
    
}
@end
